<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>项目列表</title>
    <?php PrintPageHead(); ?>
    <link href="../resource/css/hermes.css" rel="stylesheet">
    <link href="../resource/js/calendar/calendar-blue.css" type="text/css" rel="stylesheet">
    <script src="../resource/js/calendar/calendar.js" type="text/javascript"></script>
    <script src="../resource/js/hermes.js"></script>
    <style type="text/css">
       .form_d{
           width:500px;
           margin: 20px auto;
       }
    </style>
    <?php
    if (!array_key_exists("公众号ID",$_SESSION)) {
        header("Location:back.php");
    }
    $bm=new C后台管理员();

    $课程id ='';
    if(isset($_REQUEST['id']))$课程id = $_REQUEST['id'];
    if($课程id){

        $内容=pdo()->selectOne("SELECT a.*,b.`name`,c.`医院` FROM `语音课程`a LEFT JOIN `用户` b ON(a.`讲课专家id` =b.id) LEFT JOIN `医师详情` c ON(b.id = c.`用户id`)  WHERE  a.id=".$_REQUEST['id'].";");
    }


    ?>
</head>
<body>

<!-- 配置文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../ueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container', {
        toolbars: [
            [ 'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|','link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'simpleupload', 'insertimage', 'emotion', 'scrawl', 'attachment', 'map', 'gmap', 'insertframe']
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });
</script>

<div class="container-fluid">
    <?php include_once 'back_header.php'; ?>
    <div class="panel panel-primary">
        <div class="panel-heading text-center"><h3 class="panel-title"><?php if(isset($内容))echo "编辑";else echo "添加";?>视频课程</h3></div>

        <div class="form_d">
            <form action="" method="post">
                昵称:<input type="text" name="name" id="namese" style="width: 120px">
                <input type="button" onclick="selectshow()" name="select" value="搜索用户">

            </form>
        </div>

        <form action="" method="post">
            <div class="form_d"><span style="width: 180px">用   户:</span>
                <div id="xianshi">
                    <?php  if($内容){?>
                    <input type="radio" checked="checked" value="<?=$内容['讲课专家id']?>" name="专家id">
                    <?=$内容['name']?>（<?=$内容['医院']?>）
                    <?php  }?>
                </div>
                <div class="form_d"><span>推送主题:</span><input style="width: 80%;" type="text" name="theme" value="<?=@$内容['theme']?>"></div>
            <div class="form_d"><span>标题:</span><input style="width: 80%;" type="text" name="title" value="<?=@$内容['title']?>"></div>
                <div class="form_d"><span>是否是测试数据:</span>
                    <input style="" type="radio" name="is_test" value="0" checked>否&nbsp;&nbsp;
                    <input style="" type="radio" name="is_test" value="1" <?php if($内容['is_test']==1) echo checked; ?>>是
                </div>
                <div class="form_d"><span>课程提醒模板ID:</span><input style="width: 80%;" type="text" name="咨询模板ID" value="<?=@$内容['咨询模板ID']?>"></div>
                <div class="form_d"><span>课程开课通知模板ID:</span><input style="width: 80%;" type="text" name="course_notice_templateId" value="<?=@$内容['course_notice_templateId']?>"></div>
                <div class="form_d"><span>课堂人数上限:</span><!-- 加载编辑器的容器 -->
                    <input type="text" placeholder="最多报名人数，默认没有人数限制" name="课堂人数上限" value="<?=@$内容['课堂人数上限']?>"/>
                </div>
            <div class="form_d"><span>时间:</span>
            <input type="text" name="开始时间" placeholder="2016-01-12 20:00" value="<?=@$内容['开始时间']?>">~
                <input type="text" name="结束时间" placeholder="2016-01-12 22:00" value="<?=@$内容['结束时间']?>">
            </div>
            <div class="form_d"><span>视频url:</span><!-- 加载编辑器的容器 -->
                <textarea name="url"  style="width: 90%"><?=@$内容['视频url']?></textarea>
            </div>

            <div class="form_d"><span>简介:</span>
                <textarea name="简介" style="width: 90%"><?=@$内容['简介']?></textarea> </div>
            <div class="form_d"><span>内容:</span><!-- 加载编辑器的容器 -->
                <script id="container" name="content" type="text/plain"><?=@$内容['详情']?></script>
            </div>
            <div class="form_d"><input id="tijiao" type="submit" name="okn" value="提交">

                <a href="../back.php?state=back8Shipin_LessonsS">查看历史</a> </div>

        </form>
<form action="" method="post">

    请输入课程标题：<input type="text" name="content" >
    <input type="submit" id="end" name="end" value="发布">
</form>

    </div>

</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>
<script language="JavaScript">
    function selectshow(){
        var name= document.getElementById("namese").value;
        $.post('back.php?state=BackSellerAjax',{name:name,'businessFlag':'ac查找用户'},function(data) {
            document.getElementById('xianshi').innerHTML='';
            document.getElementById("xianshi").innerHTML=data;

        });

    }
$(function(){
//    $("#fasong").click(function(){
//        $(this).attr('hidden',true);
//    });
//    $("#fasong2").click(function(){
//        $(this).attr('hidden',true);
//    });

    $("#end").click(function(){
        $(this).attr('hidden',true);
    });
    $("#tijiao").click(function(){
        $(this).attr('hidden',true);
    });
})

</script>
</body>
</html>
<?php

//if(isset($_POST['fasong2'])){
//    $bm->ff发送咨询信息(1,'','失败');
//    echo "<script>alert('发送成功!');</script>";
//}
//
//if(isset($_POST['fasong'])){
//    $bm->ff公众号发送单图文信息();
//    echo "<script>alert('发送成功!');</script>";
//}



if(isset($_POST['end'])){

    if( $_REQUEST['content']==""){
        echo "<script>alert('请认真填写信息!');</script>";
    }else{
        $res=pdo()->selectOne("select * from 语音课程 where title='".trim($_REQUEST["content"])."'");

        if($res){
            $bm->fc发送图文消息_所有用户1('视频课程',$_REQUEST['content'],$res['id'],'websocket');
            echo "<script>alert('发布成功!');</script>";
        }else{
            echo "<script>alert('该课程不存在，请确认后再输入!');</script>";
        }

    }

}


if(isset($_POST['okn'])){
    if($_REQUEST['title']==''||$_REQUEST['content']==''){
        echo "<script>alert('请认真填写信息!');</script>";
    }else{
        $重复上课 = $bm->fc判断当前时间内专家有课($_REQUEST['专家id'],$_REQUEST['开始时间'],$_REQUEST['结束时间'],$课程id);
        if($重复上课>0){
            echo "<script>alert('该专家已有安排');</script>";
        }else{
            if($课程id){
                $dos= new  Do语音课程();
                $dos->set_id($_REQUEST['id']);
                $dos->set_theme($_REQUEST['theme']);
                $dos->set_title($_REQUEST['title']);
                $dos->set_咨询模板ID($_REQUEST['咨询模板ID']);
                $dos->set_详情($_REQUEST['content']);
                $dos->set_视频url($_REQUEST['url']);
                $dos->set_简介($_REQUEST['简介']);
                $dos->set_讲课专家id($_REQUEST['专家id']);
                $dos->set_开始时间($_REQUEST['开始时间']);
                $dos->set_结束时间($_REQUEST['结束时间']);
                $dos->set_咨询模板ID($_REQUEST['咨询模板ID']);
                $dos->set_course_notice_templateId($_REQUEST['course_notice_templateId']);
                $dos->set_课堂人数上限($_REQUEST['课堂人数上限']);
                $dos->set_is_test($_REQUEST['is_test']);
                //var_dump($_REQUEST['课堂人数上限']);

                pdo()->update('语音课程报名',array('用户id'=>$_REQUEST['专家id']),array('课程id'=>$_REQUEST['id'],'专家'=>'是'));
                $re=$dos->update();
                if($re){
                 //   $bm->fc发送图文消息_所有用户('视频课程',$_REQUEST['theme'],$_REQUEST['id'],'Seller17Shipin_Lessons');

                    echo "<script>alert('修改成功');location.replace(location.href);</script>";
                }else{

                    echo "<script>alert('修改失败或没有修改任何信息');</script>";
                }
            }else{
                $用户openID = pdo()->selectOne("select openID from 用户 WHERE id=".$_REQUEST['专家id']);
                $b=new CUI数据中心('Seller17Shipin_Lessons',$用户openID['openID']);
                $c用户 = new C用户($b->vo信息中心);
                $type = "课程群";
                $群id = $c用户->fc创建课程群组($_REQUEST['专家id'],3);

                $re = pdo()->insert('语音课程',array('id'=>$_REQUEST['id'],'theme'=>$_REQUEST['theme'],'title'=>$_REQUEST['title'],'咨询模板ID'=>$_REQUEST['咨询模板ID'],'详情'=>$_REQUEST['content'],'简介'=>$_REQUEST['简介'],'开始时间'=>$_REQUEST['开始时间'],'结束时间'=>$_REQUEST['结束时间'],'视频url'=>$_REQUEST['url'],'讲课专家id'=>$_REQUEST['专家id'],'type'=>'视频','群id'=>$群id,'课堂人数上限'=>$_REQUEST['课堂人数上限'],'is_test'=>$_REQUEST['is_test'],'course_notice_templateId'=>$_REQUEST['course_notice_templateId']));

                $课程id = pdo()->lastInsertId();
                $do报名 = new Do语音课程报名();
                $do报名->set_专家('是');
                $do报名->set_用户id($_REQUEST['专家id']);
                $do报名->set_课程id($课程id);
                $报名 = $do报名->insert();

                if($re &&$报名){

                    echo "<script language='javascript'>alert('添加成功!');location.replace('back.php?state=back8Shipin_LessonsS');</script>";

                }else{

                    echo "<script>alert('添加失败');</script>";
                }
             }

        }

    }

}
?>
